package com.med.meddataintegrator.admin.service.Impl;

import com.med.meddataintegrator.admin.service.OptionService;
import com.med.meddataintegrator.common.pojo.dos.OptionDo;
import com.med.meddataintegrator.common.pojo.dto.option.OptionQuery;
import com.med.meddataintegrator.common.pojo.dto.option.OptionSaveParam;
import com.med.meddataintegrator.common.mapper.OptionDoMapper;
import com.med.meddataintegrator.common.pojo.vo.option.OptionVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Slf4j
@Service
public class OptionServiceImpl implements OptionService {
    @Autowired
    OptionDoMapper optionDoMapper;
    @Override
    public List<OptionVO> selectOption(OptionQuery optionQuery) {
        log.debug("查询科目信息业务", optionQuery);
        List<OptionVO> list = optionDoMapper.select(optionQuery);
        return list;
    }

    @Override
    public void saveOption(OptionSaveParam optionSaveParam) {
        log.debug("保存科目信息业务", optionSaveParam);
        OptionDo optionDo = new OptionDo();
        BeanUtils.copyProperties(optionSaveParam, optionDo);
        if (optionSaveParam.getId() == null){
            optionDoMapper.insert(optionDo);
        }else {
            optionDoMapper.updateByPrimaryKeySelective(optionDo);
        }
    }

    @Override
    public void deleteOption(Integer id) {
        log.debug("删除科目信息业务", id);
        optionDoMapper.deleteByPrimaryKey(id);
    }
}
